//
//  SignViewController.m
//  WHB_cargo
//
//  Created by Rui on 16/1/5.
//  Copyright © 2016年 turing. All rights reserved.
//

#import "SignViewController.h"
#import "SignTableViewCell.h"
@interface SignViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
@property(nonatomic, strong)UITableView *tableView;

@property(nonatomic, strong)UITextField *textField;
@property(nonatomic, strong)UITextField *textField1;
@property(nonatomic, strong)UITextField *textField2;
@property(nonatomic,strong)UIButton *button;



@end

@implementation SignViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.tableView registerClass:[SignTableViewCell class] forCellReuseIdentifier:@"sign"];
    
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;

  
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.button];
    self.button.backgroundColor = [UIColor grayColor];
    self.button.frame = CGRectMake(310, 480, 100, 30);
    [self.button setTitle:@"获取验证码" forState:UIControlStateNormal];

    [self.button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
    self.button.layer.masksToBounds = YES;
    self.button.layer.cornerRadius = 5;

    self.textField = [[UITextField alloc]init];
    [self.view addSubview:self.textField];
    self.textField.delegate = self;

    
    self.textField1 = [[UITextField alloc]init];
    [self.view addSubview:self.textField1];
    self.textField1.delegate = self;

    self.textField2 = [[UITextField alloc]init];
    [self.view addSubview:self.textField2];
    self.textField2.delegate = self;

    
    self.textField.placeholder = @"请输入手机号";
    self.textField1.placeholder = @"请输入验证码";
    self.textField2.placeholder = @"请输入密码";
    
    
    self.textField.frame = CGRectMake(100, 400, 200, 100);
    self.textField2.frame = CGRectMake(100, 500, 200, 100);
    self.textField1.frame = CGRectMake(100, 450, 200, 100);

    [self.textField addTarget:self action:@selector(textFieldAction:) forControlEvents:UIControlEventAllEditingEvents];
    [self.textField1 addTarget:self action:@selector(textFieldAction:) forControlEvents:UIControlEventAllEditingEvents];
    [self.textField2 addTarget:self action:@selector(textFieldAction:) forControlEvents:UIControlEventAllEditingEvents];


    
    
}
- (void)textFieldAction:(UITextField *)textField{
    
    CGFloat offset = self.view.frame.size.height - (self.textField.frame.origin.y + self.textField.frame.size.height + 400);
    CGFloat offset1 = self.view.frame.size.height - (self.textField1.frame.origin.y + self.textField1.frame.size.height + 400);
    CGFloat offset2 = self.view.frame.size.height - (self.textField2.frame.origin.y + self.textField2.frame.size.height + 400);

    if (offset <= 0 || offset1 <= 0 || offset2 <= 0) {
        [UIView animateWithDuration:0.3 animations:^{
            CGRect frame = self.view.frame;
            frame.origin.y = offset;
            self.view.frame = frame;
        }];
    }
    
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    [self.textField resignFirstResponder];
    [self.textField1 resignFirstResponder];
    [self.textField2 resignFirstResponder];

    [UIView animateWithDuration:0.3 animations:^{
        CGRect frame = self.view.frame;
        frame.origin.y = 0.0;
        self.view.frame = frame;
    }];
    
    
    return YES;
}

-(void)button:(UIButton *)button
{
    NSLog(@"点击");
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SignTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"sign" forIndexPath:indexPath];
    [cell.ImageView setImage:[UIImage imageNamed:@"logo"]];
    [cell.ImageView1 setImage:[UIImage imageNamed:@"zh"]];
    [cell.ImageView2 setImage:[UIImage imageNamed:@"zc"]];
    [cell.ImageView3 setImage:[UIImage imageNamed:@"zc"]];

       return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
